package gewu.suleju.controller;

import gewu.suleju.anno.FormToken;
import gewu.suleju.model.vo.Result;
import gewu.suleju.sevice.imp.HouseDetailServiceImp;
import gewu.suleju.util.JWTUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("house")
public class HouseOnclick {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private HouseDetailServiceImp houseDetailServiceImp;
    @RequestMapping("onclick")
    @FormToken(save=true)
    public Result save(){
        return new Result("200","跳转成功");
    }
    @RequestMapping("getToken")
    public Result getToken(String token,String houseId){
        Claims claims = JWTUtil.checkJWT(token);
        if(claims == null){
            return new Result("500","请先登录");
        }
        String userId = String.valueOf(claims.get("id"));
        int a = houseDetailServiceImp.findBrokerId(Integer.parseInt(houseId));
        return new Result(a+"",(String)redisTemplate.opsForValue().get("formToken"),userId);
    }
}
